package com.example.controller;

import com.example.common.Result;
import com.example.entity.Work;
import com.example.service.WorkService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 专业信息模块前端请求接口入口
 */
@RestController
@RequestMapping("/work")
public class WorkController {
    @Resource
    private WorkService workService;
    /**
     * 增加
     */
    @PostMapping("/add")
    public Result add(@RequestBody Work work) {

        workService.add(work);
        return Result.success();
    }
/**
 * 更新
 */
    @PutMapping("/update")
    public Result update(@RequestBody Work work) {
        workService.updateByID(work);
        return Result.success();
    }

    /**
     * 分页查询接口
     */
    @GetMapping("/selectPage")
    public Result selectPage(Work work,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "5") Integer pageSize)
    {
        PageInfo<Work> pageInfo = workService.selectPage(work,pageNum,pageSize);
        return Result.success(pageInfo);
    }
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        workService.deleteById(id);
        return Result.success();
    }
    /*
     * 查询所有
     */

    @GetMapping("/selectAll")
    public Result selectAll() {
        List<Work> list = workService.selectAll();
        return Result.success(list);
    }

}